package com.mbc.mapper;

import com.mbc.dto.StrayAnimalInformationCommentsSectionDTO;
import com.mbc.vo.StrayAnimalInformationCommentsSectionVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.ArrayList;

@Mapper
public interface StrayAnimalInformationCommentSectionMapper {
    /**
     * 新增流浪动物信息评论
     *
     * @param userId     用户 ID
     * @param animalId   动物 ID
     * @param sectionDTO DTO 部分
     * @param now        现在
     * @return int
     */
    int insertStrayAnimalInformationCommentSection(Integer userId, Integer animalId,
                                                   StrayAnimalInformationCommentsSectionDTO sectionDTO,
                                                   LocalDateTime now);

    /**
     * 分页查询流浪动物信息评论区
     *
     * @param animalId 动物 ID
     * @return {@link ArrayList }<{@link StrayAnimalInformationCommentsSectionVO }>
     */
    ArrayList<StrayAnimalInformationCommentsSectionVO> selectStrayAnimalInformationCommentSection(Integer animalId);

    /**
     * 点赞
     *
     * @param animalId 动物 ID
     * @return int
     */
    @Update("update mbc_stray_animal_information_comments_section set number_of_likes = number_of_likes + 1 where animal_id = #{animalId}")
    int updateNumberOfLikes2(Integer animalId);

    /**
     * 取消点赞
     *
     * @param animalId 动物 ID
     * @return int
     */
    @Update("update mbc_stray_animal_information_comments_section set number_of_likes = number_of_likes - 1 where animal_id = #{animalId}")
    int updateNumberOfLikes1(Integer animalId);

    /**
     * 删除评论
     *
     * @param animalId 动物 ID
     * @param userId   用户 ID
     * @return int
     */
    @Delete("delete from mbc_stray_animal_information_comments_section where animal_id = #{animalId} and user_id = #{userId}")
    int deleteStrayAnimalInformationCommentSection(Integer animalId, Integer userId);
}
